﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Security;
namespace hoangnam12
{
    public partial class DangKy : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public void ShowMessage(string Content)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript'>alert('" + Content + "');location.href = 'Dangky.aspx'</script>");
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            dataprovider data = new dataprovider();

            // Ràng buộc Username
           
                string testemail = "select Email from [User] where Email = '" + TextBox3.Text + "'";
                string testuser = "select Username from [User] where Username = '" + TextBox1.Text + "'";
                if (data.ExecuteReader(testuser).HasRows)
                    Label1.Text = "Username bị trùng";
                else
                {
                    if (data.ExecuteReader(testemail).HasRows)
                        Label4.Text = "Email Đã Được Sử Dụng";
                    else
                    {
                        DateTime birth = new DateTime(Convert.ToInt32(nam.Text), Convert.ToInt32(thang.Text), Convert.ToInt32(ngay.Text));

                        string EncodePwd = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text, "MD5");
                        string gender = "Male";
                        if (this.female.Checked == true)
                            gender = "Female";
                        string sql = "insert into [User](Makhach,Ten,Ho,NamSinh,Phone,Username,Email,Password,Sex,admin) values ('','" + TextBox4.Text + "','" + TextBox5.Text + "','" + birth + "','" + TextBox8.Text + "','" + TextBox1.Text + "','" + TextBox3.Text + "','" + EncodePwd + "','" + gender + "','1')";
                        data.Executenonquery(sql);

                        ShowMessage("bạn đã đang ký thành công");
                    }
                }
        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            

        }

    }

}